<?php namespace Common\Model;
use Hdphp\Model\Model;
class Tag extends Model{
		//操作标签表
		protected $table="tag";
		//自动验证，必须通过create方法来触发
		protected $validate = array(
			array("tname","required","请输入标签名",3,3),
			array("tname","maxlen:30","标签名称不能超过30",3,3),
			array("tname","unique","标签名称不能重复",3,3),
			
		);
		/*
		 * 添加
		 * */
		public function store(){
			//执行验证
			if(!$this->create()) return false;
			$tname = explode("|", $_POST['tname']);
			//执行添加
			foreach ($tname as $v) {
			
				$this->add(array("tname"=>$v));
			}
			return true;
		}
		/*
		 * 编辑
		 * */
		 public function edit(){
		 //自动验证
		   if(!$this->create()) return false;
		 //执行编辑
		  return $this->save();
		 }
		 /*
		  * 删除
		  * */
		 public function del($tid){
		 	//删除标签表里的数据
			Db::table("article_tag")->where("tag_tid",$tid)->delete();
			//删除标签表里的数据
			$this->where('tid',$tid)->delete();
			
			
		 }
	}
